  // 为涉及到的elements层次建立front\next关系
  // let definitions = {};
  // definitions.processes = [{
  //   id: 'process0',
  //   elements: [{id: '1-01'},{id: '1-02', elements: [{id: '1-02-01'},{id: '1-02-02', elements: [{id: '1-02-02-1'}, {id: '1-02-02-2', elements: []}]},{id: '1-02-03'}]},{id: '1-03'},{id: '1-04'},{id: 
  //   '1-05', elements: [{id: '1-05-01'},{id: '1-05-02'},{id: '1-05-03', elements: [{id: 'target'}]},{id: '1-05-04'}]},{id: '1-06'}]
  // }]
  // getNodeBeforeTarget('target', definitions)
  export function getNodeBeforeTarget(id, definitions) {
    let res = [];
    let process = definitions.processes[0];
    const nodes = findTargetPathInObject(process, id)[0] ?? [];// 找到目标节点在process对象的层次关系
    console.log(nodes)
    for(let i = 0; i < nodes.length - 1; i++) {
      let node = nodes[i];
      let elements = node.elements ?? [];
      let map = buildRelationBetweenFrontAndNext(elements);// 为涉及到的层次建立节点前后关系
      let firstNode = findHeadNodes(elements)[0];
      let targetId = nodes[i + 1].id;// 这层连线的目标节点Id
      back(firstNode.next, [firstNode], map, targetId);
    }
    function back(elements, path, map, id) {
      if(path[path.length - 1]?.id === id) {
        res.push(path.slice(0, -1));
        return
      }
      if(path.length && (!path[path.length - 1].next || !path[path.length - 1].next.length)) { return }
      for(let i = 0; i < elements.length; i++) {
        if(!map[elements[i].id].next && elements[i].id !== id) { continue }
        path.push(elements[i]);
        back(elements[i].next, path, map, id);
        path.pop();
      }
    }
    return [...new Set(res.flat(Infinity))];
  }
  function findTargetPathInObject(process, id, outerObj = []) {// process传入的应该是definitions.processes[0]
  // 返回对应的路径
    let elements = process.elements;
    outerObj.push(process)
    let res = [];
    function back(path, elements) {
      if(path[path.length - 1]?.id === id) {
        res.push(path.slice(0));
        return
      }
      if(path.length && (!path[path.length - 1].elements || !path[path.length - 1].elements.length)) {
        return
      }
      for(let i = 0; i < elements.length; i++) {
        if(!ifContinue(elements[i])) { continue }
        path.push(elements[i]);
        back(path, elements[i].elements ?? []);
        path.pop();
      }
    }
    function ifContinue(node) {
      if(node.id === id || node.elements?.length) return true
      return false
    }
    back([process], elements);
    return res
  }
  function buildRelationBetweenFrontAndNext(elements, idToNodeMap = {}) {// 给当前层次的elements的节点建立前后关系, 返回所有节点的map{id：node}
  // 先找到当前层次的起始节点
  if(!elements || !elements.length) { return idToNodeMap }
  for (let i = 0; i < elements.length; i++) {
    const node = elements[i];
    if (node.tagName === 'sequenceFlow') {
      const { sourceRef, targetRef } = node;
      if (!idToNodeMap[sourceRef]) {
        idToNodeMap[sourceRef] = { vNode: true };
      }
      if(!idToNodeMap[sourceRef].next) { idToNodeMap[sourceRef].next = []; }
      let set = new Set(idToNodeMap[sourceRef].next);
      set.add(targetRef);
      idToNodeMap[sourceRef].next = [...set];
    } else {
      // 非连线元素;
      if (!idToNodeMap[node.id]) {
        idToNodeMap[node.id] = node;
      } else {
        if (idToNodeMap[node.id].vNode) {
          // 非真实节点, 替换成真实的
          node.next = idToNodeMap[node.id].next;
        }
        idToNodeMap[node.id] = node;
      }
    }
  }
  for(let key in idToNodeMap) {
    if(!idToNodeMap[key].next) { continue }
    for(let i = 0; i < idToNodeMap[key].next.length; i++) {
      let id = idToNodeMap[key].next[i];
      idToNodeMap[key].next[i] = idToNodeMap[id];
      if(!idToNodeMap[id].front) {
        idToNodeMap[id].front = [];
      }
      let set = new Set(idToNodeMap[id].front);
      set.add(idToNodeMap[key]);
      idToNodeMap[id].front = [...set];
    }
  }
  return idToNodeMap
}
function findHeadNodes(elements) {// 传入一层elements，返回当前elements的头结点（没有sequence指向的）
  let targetIds = [];
  let heads = [];
  if (elements.length === 1) { return [...elements] }
  for(let i = 0; i < elements.length; i++) {
    let node = elements[i];
    if(node.tagName === 'sequenceFlow') {
      const { targetRef } = node;
      targetIds.push(targetRef);
    }
  }
  targetIds = [...new Set(targetIds)];
  for(let i = 0; i < elements.length; i++) {
    if(elements[i].tagName !== 'sequenceFlow' && !targetIds.includes(elements[i].id)) {
      heads.push(elements[i]);
    }
  }
  return heads;
}